#include "process.h"
#include <string.h>
#include <unistd.h>

#define SIZE 101
#define STYLE '='

char buffer[SIZE] = {'\0'};
const char* lable = "|/-\\";
int id = 0;

void FlashProcess(double total,double cur)
{
  int len = strlen(lable);
  if(cur > total)
  {
    cur = total;
  }
  double rate = cur / total * 100;
  int cnt = (int)rate;
  int i = 0;
  for(;i<cnt;i++)
  {
    buffer[i] = STYLE;
  }
  id++;
  id %= len;
  //刷新
  printf("[%-100s][%.1lf%%][%c]\r",buffer,rate,lable[id]);
  fflush(stdout);
  if(cur == total)
  {
    printf("\n");
  }
}
















//version1
//void process()
//{
//  const char* lable = "|/-\\";
//  int len = strlen(lable);
//  char processbuffer[SIZE];
//  memset(processbuffer,'\0',sizeof processbuffer);
//  int cnt = 0;
//  while(cnt <= 100)
//  {
//    printf("[%-100s][%d%%][%c]\r",processbuffer,cnt,lable[cnt%len]);
//    fflush(stdout);
//    processbuffer[cnt] = STYLE;
//    usleep(50000);
//    cnt++;
//  }
//  printf("\n");
//}
